package com.googlecode.boliang.q10;

import java.util.ArrayList;
import java.util.List;

public class RetrieveBTreeByLevel {

	List<BTree> outputList = new ArrayList<BTree>();

	public List<BTree> getBTreeNodeByLevel(BTree rootNode) {

		int i = 0;
		outputList.add(rootNode);

		while (outputList.get(i) != null) {
//			if (rootNode.leftChildNode != null)
				outputList.add(rootNode.leftChildNode);
//			if (rootNode.rightChildNode != null)
				outputList.add(rootNode.rightChildNode);
			i++; 
			rootNode = outputList.get(i); 
		}

		return outputList;
	}
}
